package com.sunday.aomicaichang.ui.my;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.sunday.common.base.BaseActivity;
import com.sunday.common.utils.ToastUtils;
import com.sunday.aomicaichang.R;
import com.sunday.aomicaichang.base.BaseApp;
import com.sunday.aomicaichang.widgets.PayPwdEditText;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yun_sheng on 2017/6/6.
 */

public class UpdatePaySetting2Activity extends BaseActivity {

    @Bind(R.id.edt_password)
    PayPwdEditText edtPassword;
    @Bind(R.id.tv_phone)
    TextView tvPhone;
    @Bind(R.id.title)
    TextView title;

    private String mobile;
    private String code;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set_pay2);
        ButterKnife.bind(this);
        code=getIntent().getStringExtra("code");
        mobile = BaseApp.getInstance().getMember().getMobile();
        if (mobile != null)
            tvPhone.setText(mobile);
        init();
        title.setText("修改支付密码");
    }

    private void init() {
        edtPassword.initStyle(R.drawable.edit_by_bg, 6, 0.33f, R.color._999, R.color._999, 20);
        edtPassword.setOnTextFinishListener(new PayPwdEditText.OnTextFinishListener() {
            @Override
            public void onFinish(String str) {
                // 要验证的字符串
                // 正则表达式规则
                String regEx = "^(?=.*\\d+)(?!.*?([\\d])\\1{5})[\\d]{6}$";
                Pattern pattern = Pattern.compile(regEx);
                // 忽略大小写的写法
                // Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
                Matcher matcher = pattern.matcher(str);
                // 查找字符串中是否有匹配正则表达式的字符/字符串
                final boolean rs = matcher.find();
                if (rs) {
                    Intent intent = new Intent(mContext, UpdatePaySetting3Activity.class);
                    intent.putExtra("code",code);
                    intent.putExtra("password",str);
                    startActivity(intent);
                    finish();
                } else {
                    ToastUtils.showToast(mContext, "支付密码不能是重复、连续的数字!");
                    return;
                }
            }
        });

    }

}

